
version 15
capture log close
set more off
clear
clear matrix
clear mata

if c(username)=="WB485280" {
		glo rootdir		"C:\Users\wb485280\OneDrive - WBG\radicalization"
		}
if c(username)=="WB382635" {
		glo rootdir		"C:\Users\wb382635\Dropbox\Unemp & daesh"
		}
if c(username)=="WB452275" {
		glo rootdir		"C:\Users\WB452275\Dropbox\Projects\Unemp & daesh"
		}
if c(username)=="sarurchaudhary" {
		glo rootdir		"/Users/sarurchaudhary/Dropbox/Unemp & daesh"
		}
if c(username)=="kartikabhatia" {
			glo rootdir		"/Users/kartikabhatia/Dropbox/Before2019/Unemp & daesh"
			}
			
		glo	datadir     "${rootdir}/Data/Raw data"
		glo outdir		"${rootdir}/Data/Working datasets"
		glo dodir		"${rootdir}/Dofiles"
        
		cd "${outdir}"
		
	    log using qog_prep, replace t

* ------------------------------------------------------------------------------
* Date : July 2017 [chkd oct 2021]


* Project : Mena Economic Monitor, Fall 2016 edition (MNACE, The World Bank)


* This do file prepares the WDI database for merge

* Database used : qog_bas_ts_jan16.dta


* Output : qog.dta

* ------------------------------------------------------------------------------


*                      ---------------------------
*                      ----------QOG Data---------
*                      ---------------------------

use "${datadir}/qog_bas_ts_jan16.dta", clear 

* Keeping years after 2004

keep if year>=2004

/* More careful categorization of countries
and their boundaries is required if we want to use the historical data. */


 * Droping islands and small nations

 drop if cname=="Andorra"
  drop if cname=="Antigua and Barbuda"
  drop if cname=="Bahamas"
  drop if cname=="Barbados"
  drop if cname=="Brunei"
  drop if cname=="Cape Verde"
 replace cname="Cyprus" if cname=="Cyprus (-1974)"
 replace cname="Northern Cyprus" if cname=="Cyprus (1975-)"
 replace cname="Ivory Coast" if cname=="Cote d'Ivoire"
 replace cname="Congo Kinshasa" if cname=="Congo, Democratic Republic"
 replace cname="Congo Brazzaville" if cname=="Congo"
 drop if cname=="Czechoslovakia"
 drop if cname=="Dominica"
  drop if cname=="Ethiopia (-1992)"
  drop if cname=="Fiji"
  drop if cname=="France (-1962)"
  drop if cname=="Germany, East"
  drop if cname=="Germany, West"
  drop if cname=="Grenada"
 replace cname="North Korea" if cname=="Korea, North"
 replace cname="South Korea" if cname=="Korea, South"
  drop if cname=="Liechtenstein"
  drop if cname=="Malaysia (-1965)"
  drop if cname=="Marshall Islands"
  drop if cname=="Micronesia"
  drop if cname=="Monaco"
  drop if cname=="Nauru"
 drop if cname=="Pakistan (-1970)"
 drop if cname=="Palau"
 drop if cname=="Papua New Guinea"
 drop if cname=="Samoa"
 drop if cname=="San Marino"
 drop if cname=="Sao Tome and Principe"
 drop if cname=="Serbia and Montenegro"
 drop if cname=="Seychelles"
 drop if cname=="Solomon Islands"
 drop if cname=="St Kitts and Nevis"
 drop if cname=="St Lucia"
 drop if cname=="St Vincent and the Grenadines"
 drop if cname=="Timor-Leste"
 drop if cname=="Tibet"
 drop if cname=="Tonga"
 drop if cname=="Tuvalu"
 drop if cname=="USSR"
 drop if cname=="Vanuatu"
 drop if cname=="Vietnam, North"
 drop if cname=="Vietnam, South"
 drop if cname=="Yemen, North"
 drop if cname=="Yemen, South"
 drop if cname=="Yugoslavia"
drop if cname=="South Sudan" & year<=2011
 drop if cname=="Sudan (-2011)"
drop if cname=="Kiribati"
drop if cname=="Maldives"

rename  version qog_version

 * Adding countries that are in WDI and gallup but not in polity4

 insobs 6, before(1)
 replace cname = "Hong Kong SAR, China" in 1
 replace year = 2005 in 1
 replace cname = "Kosovo" in 2
 replace year = 2005 in 2
 replace cname = "Nagorno Karabakh" in 3
 replace year = 2005 in 3
 replace cname = "Palestine" in 4
 replace year = 2005 in 4
 replace cname = "Puerto Rico" in 5
 replace year = 2005 in 5
 replace cname = "Somaliland" in 6
 replace year = 2005 in 6
 
* Changing some names in countryname


 replace cname = "Egypt, Arab Rep." if cname =="Egypt"
		replace cname = "Gambia, The" if cname=="Gambia"
        replace cname = "Iran, Islamic Rep." if cname =="Iran"
		replace cname = "Lao PDR" if cname =="Laos"
		replace cname = "Macedonia, FYR" if cname =="Macedonia"
		replace cname = "Russian Federation" if cname =="Russia"
		replace cname = "Yemen, Rep." if cname =="Yemen"
		replace cname = "Syrian Arab Republic" if cname =="Syria"
 
 sort cname, stable
 encode cname, gen(ctry)
sort ctry year
 
 note
 note drop _dta
note: keeping sudan and south sudan after 2012 (QoG)
note: keeping obs after 2004 (QoG)

save  "${outdir}/qog.dta", replace

log close
